﻿ menuItems = new Array();
 menuItemNum = 0;
 menuWidth = 145;
 menuHeight = 167;
 menuDelay = 100;
 menuSpeed = 2;
 menuOffset = 2;
 function addMenuItem(text, url, img){
	if (img){
		menuItems[menuItemNum] = new Array(text, url, img);
	}
	else if (text){
		menuItems[menuItemNum] = new Array(text, url);
	}
	else{
		menuItems[menuItemNum] = new Array();
	}
	menuItemNum ++;
 }

function menu(){
	 imgpath = "/Admin/Images/ToolBar/";
	
	 addMenuItem("剪切","7",imgpath+"Button.Cut.gif");
	 addMenuItem();
	 addMenuItem("复制","8",imgpath+"Button.Copy.gif");
	 addMenuItem("粘贴","9",imgpath+"Button.Paste.gif");
	 addMenuItem();
	 addMenuItem("删除","3",imgpath+"Button.Delete.gif");
	 addMenuItem();
	 addMenuItem("刷新(F5)","2",imgpath+"Button.Refresh.gif");
	 addMenuItem();
	 addMenuItem("生成预览","1",imgpath+"Button.Blank.gif");
	
	 if (window.navigator.appName == "Microsoft Internet Explorer" 
	 && window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE") + 5, 
	 window.navigator.appVersion.indexOf("MSIE") + 8) >= 5.5)
	 {
		isIe = 1;
	 }
	 else{
		isIe = 0;
	 }
	 if (isIe){
		menuContent = '<table id="rightMenu" width="0" height="0" cellspacing="0" cellpadding="0" '
		+ 'style="font:menu;color:menutext;"><tr height="1"><td style="background:threedlightshadow" colspan="4">'
		+ '</td><td style="background:threeddarkshadow"></td></tr><tr height="1">'
		+ '<td style="background:threedlightshadow"></td><td style="background:threedhighlight" colspan="2">'
		+ '</td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr>'
		+ '<tr height="10"><td style="background:threedlightshadow"></td><td style="background:threedhighlight">'
		+ '</td><td style="background:threedface"><table cellspacing="0" cellpadding="0" '
		+ 'style="font:menu;color:menutext;cursor:default;">';
		for (m=0;m<menuItems.length;m++){
			var elementId = "";
			var onclick = "";
			if ( menuItems[m][0] && menuItems[m][2] ){
				if ( menuItems[m][1].length > 0 ){
					switch (parseInt(menuItems[m][1])){				
						case 7:
							elementId = "cut7";	
							onclick = "top.menuOnclick('"+elementId+"')"; 
							break;
						case 8:
							elementId = "copy8"; 
							onclick = "top.menuOnclick('"+elementId+"')"; 
							break;
						case 9:
							elementId = "paste9"; 
							onclick = "top.menuOnclick('"+elementId+"')"; 
							 break;
						case 3:
							elementId = "delete3"; 
							onclick = "top.menuOnclick('"+elementId+"')"; 
							break;							 							 												
						case 2:
							elementId = "refresh2";	
							onclick = "top.window.location.reload();"; 
							break;	
						case 1:
							elementId = "blank1";
							onclick = "parent.window.open('Preview.aspx');"; 
							break;
					}		
				}
				menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';'
				+ 'this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'threedface\';'
				+ 'this.style.color=\'menutext\';" style="cursor:hand" id="onclick'+elementId+'" onclick="'+onclick
				+'" value=""><td style="background:threedface" width="1"></td><td width="30"><img id="img'
				+elementId+'" src="'+menuItems[m][2]+'"></td><td><a id="'+elementId+'">'+menuItems[m][0]
				+'</a></td><td width="65"></td><td style="background:threedface" width="1"></td></tr>';
			}
			else{
				menuContent += '<tr><td colspan="5" height="4"></td></tr><tr><td colspan="5">'
				+ '<table cellspacing="0"><tr><td width="2" height="1"></td>'
				+ '<td width="0" height="1" style="background:threedshadow"></td><td width="2" height="1">'
				+ '</td></tr><tr><td width="2" height="1"></td><td width="100%" height="1" style="background:threedhighlight">'
				+ '</td><td width="2" height="1"></td></tr></table></td></tr><tr><td colspan="5" height="3"></td></tr>';
			}
		}
		menuContent += '</table></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td>'
		+ '</tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight">'
		+ '</td><td style="background:threedface"></td><td style="background:threedshadow"></td>'
		+ '<td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow">'
		+ '</td><td style="background:threedshadow" colspan="3"></td><td style="background:threeddarkshadow"></td></tr>'
		+ '<tr height="1"><td style="background:threeddarkshadow" colspan="5"></td></tr></table>';
	}
	else
		menuContent = "";
	return menuContent;	
 }
 
 menuPopup = window.createPopup();
 menuPopup.document.body.innerHTML = menu();		

 function showMenu()
 {
 	var f = parent.document.all.isAvailMenu.value;
 	var UnitID = parent.document.all.UnitID.value;
 	setMenuItem(f, "cut7", "剪切", "funCutUnit("+UnitID+");");
 	setMenuItem(f, "copy8", "复制", "funCopyUnit(" + UnitID + ");");
 	setMenuItem(f, "paste9", "粘贴", "funPaste(" + UnitID + ");");
 	setMenuItem(f, "delete3", "删除", "top.deleteUnit('" + UnitID + "');");
 	
	menuXPos = event.clientX + menuOffset;
	menuYPos = event.clientY + menuOffset;
	menuXIncrement = menuWidth / menuSpeed;
	menuYIncrement = menuHeight / menuSpeed;
	menuTimer = setTimeout("openMenu(0,0)", menuDelay);
	return false;
 }
 function funCopyUnit(UnitID)
 {
     var content = "C$" + UnitID;
 	document.all.copyobject.value = content;
	textRange = document.all.copyobject.createTextRange();
	textRange.execCommand("Copy");
 }

 function funCutUnit(UnitID)
 {
     var content = "X$" + UnitID;
 	document.all.copyobject.value = content;
	textRange = document.all.copyobject.createTextRange(); 
	textRange.execCommand("Copy"); 
 }

 function funPaste(UnitID)
 {
    //var paste = window.clipboardData.getData("Text"); 	
    var paste = document.all.copyobject.value;
 	var Type= paste.substring(0,1);
 	var OldUnitID = paste.substring(2);
	if (UnitID!=OldUnitID)
	{
	    top.delete_window_ifram.location = "/Admin/Template/Operate/UnitSetting.aspx?Action=Unit" + Type + "&OldUnitID=" + OldUnitID + "&UnitID=" + UnitID;
		top.window.location.reload();
	}
 }
 
 function openMenu(height, width)
 {
	iHeight = height;
	iWidth = width;
	menuPopup.show(menuXPos, menuYPos, iWidth, iHeight, document.body);
	if ( iHeight < menuHeight ){
		menuTimer = setTimeout("openMenu(iHeight + menuYIncrement, iWidth + menuXIncrement)", 1);
	}
	else{
		clearTimeout(menuTimer);
	}
 }
 function setMenuItem(flag, textId, text, onclick){
  	var txt = menuPopup.document.getElementById(textId).innerText;
	if (txt==text){
		var name = textId.substring(0,textId.length-1);
		var imgpath = "/Admin/Images/ToolBar/";
		if (flag=="0")
		{
			menuPopup.document.getElementById(textId).style.color = "#cccccc";
			menuPopup.document.getElementById("onclick"+textId).style.cursor = "";
			menuPopup.document.getElementById("onclick"+textId).value = "";
			menuPopup.document.getElementById("img"+textId).src = imgpath + "Button."+name+"2.gif";
		}
		else{
			menuPopup.document.getElementById(textId).style.color = "#000000";
			menuPopup.document.getElementById("onclick"+textId).style.cursor = "hand";
			menuPopup.document.getElementById("onclick"+textId).value = onclick;
			menuPopup.document.getElementById("img"+textId).src = imgpath + "Button."+name+".gif";
		}
	}
 }
 function menuOnclick(textId){
 	var onclick = menuPopup.document.getElementById("onclick"+textId).value;
 	if (onclick=="" && onclick.length<5)
 		return;
 	else
 		eval(onclick);
 }
 if (isIe){ //显示菜单
	document.oncontextmenu = showMenu;
 }

 function deleteUnit(UnitID) {
	if (confirm('您确定需要删除当前单元的设置吗？'))	{
	    top.delete_window_ifram.location = "/Admin/Template/Operate/UnitSetting.aspx?Action=UnitDel&UnitID=" + UnitID;
		top.window.location.reload();
	}
 }

 function init(ColumnID, UnitName, UnitID, StyleID, ModalType, isAvailMenu) {
    document.all.ColumnID.value = ColumnID;
    document.all.UnitID.value = UnitID;
    document.all.UnitName.value = UnitName;
    document.all.StyleID.value = StyleID;
    document.all.ModalType.value = ModalType;
	document.all.isAvailMenu.value = isAvailMenu;
}
/*************************************************
描述：编辑单元标签
作者：Apollo
属性：UnitID    单元序号
      StyleID   风格序号
      ModalType 模板类型：0-首页模板，1-列表模板，2-内页模板
时间：2009-12-15
*************************************************/
function OpenUnitSettingWindow(UnitID, UnitName, templateID, ModuleType,styleID) {
    var formData = "/Admin/Template/OpenUnitSetting.aspx?UnitID=" + UnitID + "&UnitName=" + escape(UnitName) + "&TemplateID=" + templateID + "&StyleID=" + styleID + "&ModuleType=" + ModuleType;
	var path = "parent"
	showTB( formData , 750, 480, "模板单元设置",path);
}
